package com.hehui.partimejob.activity.ques;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.widget.TextView;

import com.hehui.partimejob.BaseActivity;
import com.hehui.partimejob.R;
import com.hehui.partimejob.js.ques.EditQuesItemJSFace;
import com.hehui.partimejob.js.JSBean.QuesItem;
import com.hehui.partimejob.uitls.LiveDataBus;
import com.hehui.partimejob.view.BaseWebView;

public class EditQuesItemActivity extends BaseActivity {
    private TextView save;
    private WebView wv;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        BaseWebView baseWebView = new BaseWebView(wv);
        baseWebView.addJavascriptInterface(new EditQuesItemJSFace(A));
        baseWebView.loadFromAsset("editQuesItem.html");
        baseWebView.setListener(new BaseWebView.OnBaseWebViewListener() {
            @Override
            public void onPageFinished(BaseWebView webView) {
                webView.executeJsFunction("app.setType", getIntent().getStringExtra("type"));
            }
        });
        getNavView().getBack().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                baseWebView.executeJsFunction("app.showGlobalDialog");
            }
        });

        save.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                baseWebView.executeJsFunction("app.save", new BaseWebView.CallBackFromJS<QuesItem>() {
                    @Override
                    public void valueCallback(QuesItem value) {
                        LiveDataBus.getInstance().with("quesData", QuesItem.class).setValue(value);
                        finish();

                    }
                });
            }
        });
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_ques_edit_choose;
    }

    @Override
    public void init() {
        Intent intent = getIntent();
        String type = intent.getStringExtra("type");
        getNavView().setTitle(type).getNav().setBackgroundColor(getColor(R.color.priBlue));
        TextView save = new TextView(A);
        save.setText(R.string.save);
        save.setTextColor(getColor(R.color.white));
        getNavView().getNavRightView().addView(save);
        this.save = save;
        wv = (WebView) findViewById(R.id.wv);
    }
}